#!/bin/bash
#***********************************
#* CreateTime 2024-01-12
#* scriptname: check_ssl.sh
#* email: 10168386@qq.com
#* version: v0.1
#* Author : Zheng Jun
#***********************************
#### new payment project for dianshu ###
sudo apt install libxml2-utils -y
SERVCER_JAR='dianshu-payment-service-3.0.0-SNAPSHOT.jar'
DIR="/home/ubuntu/newpayment"
Log_Path="/home/ubuntu/newpayment/logs/newpayment.log"
### Java Paths ###
export JAVA_HOME=/usr/lib/jdk/jdk1.8.0_311
export JAVA=$JAVA_HOME/bin/java
export PATH=${JAVA_HOME}/bin:$PATH

### 判断 dianshu-payment pid 并杀死进程###
_pid=$(ps -ef | grep java | grep $SERVCER_JAR |awk '{print $2}')
echo "kill ------>"$SERVCER_JAR "pid---->" $_pid
[ -n "$_pid" ] && kill -9 $_pid
#创建项目jar包工程目录

if [ ! -d $DIR ];then
  mkdir -p $DIR/{jar,logs}
fi
CONFIG_FILE="./scripts/new_dianshu.xml"

# 解析XML文件，提取Java和应用程序参数
JAVA_OPTS=$(xmllint --xpath "/configuration/newpayment/javaOptions/option/text()" $CONFIG_FILE)
APP_OPTS=$(xmllint --xpath "/configuration/newpayment/appOptions/option/text()" $CONFIG_FILE)
# 将 &amp; 转换回 &
APP_OPTS=${APP_OPTS//&amp;/&}
# 构建启动命令
CMD="nohup java -jar $JAVA_OPTS $APP_OPTS -jar $DIR/jar/$SERVCER_JAR > "$Log_Path" 2>&1 &"

# 执行命令
eval $CMD